package com.da.web.sys_user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.da.common.Result;
import com.da.web.dorm_build.service.DormBuildService;
import com.da.web.dorm_repair.entity.DormRepair;
import com.da.web.dorm_repair.service.DormRepairService;
import com.da.web.school_class.sevice.SchoolClassService;
import com.da.web.school_student.service.SchoolStudentService;
import com.da.web.sys_user.entity.TotalVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author da
 * @time 2023/12/16 上午 8:40
 */
@RestController
@RequestMapping("/api/home")
public class SysHomeController {
    @Autowired
    private SchoolClassService schoolClassService;
    @Autowired
    private SchoolStudentService schoolStudentService;
    @Autowired
    private DormRepairService dormRepairService;
    @Autowired
    private DormBuildService dormBuildService;

    @GetMapping("/getTotal")
    public Result getTotal() {
        TotalVo vo = new TotalVo();
        //班级总数
        long count = schoolClassService.count();
        vo.setClassCount(count);
        //学生总数
        long count1 = schoolStudentService.count();
        vo.setStuCount(count1);
        //待维修总数
        QueryWrapper<DormRepair> query = new QueryWrapper<>();
        //状态为 0 时说明处于待维修状态
        query.lambda().eq(DormRepair::getStatus, "0");
        long count2 = dormRepairService.count(query);
        vo.setRepairCount(count2);
        //楼宇总数
        long count3 = dormBuildService.count();
        vo.setBuildCount(count3);
        return Result.success("查询成功", vo);
    }
}
